using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using FrameWorkSystem.BusinessLayer.DataLayer;

namespace FrameWorkSystem.BusinessLayer
{
    public class Sys_UsersFactory
    {

        #region data Members

        Sys_UsersSql _dataObject = null;

        #endregion

        #region Constructor

        public Sys_UsersFactory()
        {
            _dataObject = new Sys_UsersSql();
        }

        #endregion


        #region Public Methods

        /// <summary>
        /// Insert new Sys_Users
        /// </summary>
        /// <param name="businessObject">Sys_Users object</param>
        /// <returns>true for successfully saved</returns>
        public bool Insert(Sys_Users businessObject)
        {
            if (!businessObject.IsValid)
            {
                //Pthrow new InvalidBusinessObjectException(businessObject.BrokenRulesList.ToString());
            }


            return _dataObject.Insert(businessObject);

        }

        /// <summary>
        /// Update existing Sys_Users
        /// </summary>
        /// <param name="businessObject">Sys_Users object</param>
        /// <returns>true for successfully saved</returns>
        public bool Update(Sys_Users businessObject)
        {
            if (!businessObject.IsValid)
            {
                //Pthrow new InvalidBusinessObjectException(businessObject.BrokenRulesList.ToString());
            }


            return _dataObject.Update(businessObject);
        }

        /// <summary>
        /// get Sys_Users by primary key.
        /// </summary>
        /// <param name="keys">primary key</param>
        /// <returns>Student</returns>
        public Sys_Users GetByPrimaryKey(Sys_UsersKeys keys)
        {
            return _dataObject.SelectByPrimaryKey(keys); 
        }
        public bool CheckExistUser(string Uname)
        {
            //string crUname = AppCryptor.Cryptor.Encrypt(Uname);
            return _dataObject.SelectByPrimaryKey(new Sys_UsersKeys(Uname)) != null;
        }
        public Sys_Users CheckUser(string Uname, string Pwd, DateTime date)
        {            
            string crPw = AppCryptor.Cryptor.Encrypt(Pwd);
            return _dataObject.CheckUser(Uname, crPw, date);
        }
        /// <summary>
        /// get list of all Sys_Userss
        /// </summary>
        /// <returns>list</returns>
        public List<Sys_Users> GetAll()
        {
            return _dataObject.SelectAll(); 
        }

        /// <summary>
        /// get list of Sys_Users by field
        /// </summary>
        /// <param name="fieldName">field name</param>
        /// <param name="value">value</param>
        /// <returns>list</returns>
        public List<Sys_Users> GetAllBy(Sys_Users.Sys_UsersFields fieldName, object value)
        {
            return _dataObject.SelectByField(fieldName.ToString(), value);  
        }

        /// <summary>
        /// delete by primary key
        /// </summary>
        /// <param name="keys">primary key</param>
        /// <returns>true for succesfully deleted</returns>
        public bool Delete(Sys_UsersKeys keys)
        {
            return _dataObject.Delete(keys); 
        }

        /// <summary>
        /// delete Sys_Users by field.
        /// </summary>
        /// <param name="fieldName">field name</param>
        /// <param name="value">value</param>
        /// <returns>true for successfully deleted</returns>
        public bool Delete(Sys_Users.Sys_UsersFields fieldName, object value)
        {
            return _dataObject.DeleteByField(fieldName.ToString(), value); 
        }

        #endregion

    }
}
